package work;

import java.util.*;

public class Test08 {
}




class Solution08_1 {
    /**
     * Note: 类名、方法名、参数名已经指定，请勿修改
     *
     *
     *
     * @param order_list int整型 一维数组
     * @return int整型
     */
    public int statistics(int[] order_list) {
        // write code here
        int length = order_list.length;
        int sum = 0;
        if (length < 4){
            for (int order : order_list) {
                sum+=order;
            }
        }else {
            mergeSort(order_list,0, length -1);
            for (int i = 0; i < 3; i++) {
                sum+=order_list[i];
            }
        }


        return sum;
    }

    //归并排序
    public void mergeSort(int[] arr,int left,int right){
        if (left >= right){
            return;
        }
        int mid = (left + right) / 2;
        mergeSort(arr,left,mid);
        mergeSort(arr,mid+1,right);
        merge(arr,left,mid,right);
    }

    public void merge(int[] arr,int left,int mid,int right){
        int[] temp = new int[right - left + 1];
        int i = left;
        int j = mid + 1;
        int k = 0;
        while (i <= mid && j <= right){
            temp[k++] = arr[i] >= arr[j] ? arr[i++] : arr[j++];
        }

        while (i <= mid){
            temp[k++] = arr[i++];
        }
        while (j <= right){
            temp[k++] = arr[j++];
        }
        System.arraycopy(temp, 0, arr, left, temp.length);
    }
}